package com.example.baiguangsystem.mapper;

import com.example.baiguangsystem.entity.Author;
import com.example.baiguangsystem.entity.Book;
import org.apache.ibatis.annotations.*;

/**
 * 作者dao类
 *
 * @Author: 27641
 * @ProjectName: BaiGuangSystem
 * @Date: 2022/02/04/13:05
 * @noinspection SpellCheckingInspection
 */
@Mapper
public interface AuthorMapper {

    /**
     * 根据作者Id查看作者信息
     *
     * @param authorId 需要查找的作者Id
     * @return 查询结果
     */
    @Select("select * from author where author_id = #{authorId}")
    public Author selectAuthorById(@Param("authorId") Integer authorId);

    /**
     * 根据作者名字查看作者信息
     *
     * @param authorName 需要查看的作者名字
     * @return 查询结果
     */
    @Select("select * from author where author_name = #{authorName}")
    public Author selectAuthorByName(@Param("authorName") String authorName);

    /**
     * 新增作者业务实现
     *
     * @param author 需要新增的作者
     * @return 新增成功的条数
     */
    @Insert("insert into author value(#{author.authorId},#{author.authorName},#{author.authorSex}," +
            "#{author.authorAge},#{author.authorDate},#{author.authorOverview})")
    public int newAddAuthor(@Param("author") Author author);


    /**
     * 根据作者Id删除作者信息
     *
     * @param authorId 需要删除的作者Id
     * @return 删除成功的条数
     */
    @Delete("delete from author where author_id = #{authorId}")
    public int deleteAuthorById(@Param("authorId") Integer authorId);

    /**
     * 修改作者信息
     *
     * @param author 需要修改的作者信息
     * @return 修改成功的条数
     */
    @Update("update author set author_name=#{author.authorName},author_sex=#{author.authorSex}," +
            "author_age=#{author.authorAge},author_date=#{author.authorDate}," +
            "author_overview=#{author.authorOverview} where author_id=#{author.authorId}")
    public int updateAuthorById(@Param("author") Author author);
}
